<?php 
use com\soka\SokaModel;

class Planilla_Mdl extends SokaModel
{
	public function getEmpleadoProyecto($criterio) {
		$stm = $this->_db->prepare("CALL sp_empleado_proyecto('{$this->id()}' , '{$criterio}' )");
	    $stm->execute();
		while($result = $stm->fetch(\PDO::FETCH_OBJ)) {
			$rows[] = array('value'=> $result->numero_identidad.','. $result->primer_nombre .' '. $result->primer_apellido
				, 'id'=> $result->trabajador_id);
		}	
		return $rows;
	}

	public function get() {
		try {
	        $result = $this->_db->prepare("CALL nomina_trab");
	        $result->execute();
	        while ($row = $result->fetch(\PDO::FETCH_ASSOC))
				$data[] = $row;
        } catch (\PDOException $e) {
            print "Error!: " . $e->getMessage() . "<br/>";
        	die();
        }
        return $data;
	}

	public function verify($_entrada,$_salida){
		try {
			$result = $this->_db->query("SELECT id FROM planilla WHERE entrada='".$_entrada."' AND salida ='".$_salida."' ");
	        $result->execute();
	        if($result->rowCount() > 0) {
	        	$r = $result->fetch(\PDO::FETCH_OBJ);
	        	$data['id'] = $r->id;
	        	$data['success']  = true;
	 		} else {
	 			return array();
	 		}
        } catch (\PDOException $e) {
            print "Error!: " . $e->getMessage() . "<br/>";
        	die();
        }
        return $data;
	}	

	public function ultimaPlanilla(){
		try {
	        $result = $this->_db->prepare("CALL sp_ultima_planilla");
	        $result->execute();
	        while ($row = $result->fetch(\PDO::FETCH_ASSOC))
				$data[] = $row;
        } catch (\PDOException $e) {
            print "Error!: " . $e->getMessage() . "<br/>";
        	die();
        }
        return $data;
	}
	
}